package jgs1904.mapper;

import jgs1904.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 墨苍璃
 */
@Mapper
public interface UserMapper {

    /**
     * 根据用户名获取用户信息
     *
     * @param uname
     * @return
     */
    @Select("select * from user where uname=#{uname}")
    User selUserInfoMapper(@Param("uname") String uname);


    /**
     * 查询当前用户的权限信息
     *
     * @param uname
     * @return
     */
    @Select("SELECT aname FROM authority WHERE aid IN(SELECT aid FROM authority_role WHERE rid IN (SELECT rid FROM user_role WHERE uid IN (SELECT uid FROM `user` WHERE uname =#{uname})))")
    List<String> selPowerInfoMapper(@Param("uname") String uname);


    /**
     * 获取当前用户的角色信息
     *
     * @param uname
     * @return
     */
    @Select("SELECT rname FROM role WHERE rid IN ( SELECT  rid  FROM  user_role WHERE uid IN ( SELECT uid FROM `user` WHERE uname =#{uname}))")
    List<String> selRoleInfoMapper(@Param("uname") String uname);

}
